<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{.title}}</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        .order-card {
            transition: all 0.3s ease;
            border-left: 4px solid #007bff;
        }
        .order-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
        }
        .status-badge {
            font-size: 0.8em;
            padding: 0.25em 0.5em;
        }
        .status-pending { background-color: #ffc107; color: #000; }
        .status-confirmed { background-color: #28a745; color: #fff; }
        .status-paid { background-color: #17a2b8; color: #fff; }
        .status-cancelled { background-color: #dc3545; color: #fff; }
        .status-completed { background-color: #6c757d; color: #fff; }
        
        .payment-status-pending { background-color: #ffc107; color: #000; }
        .payment-status-paid { background-color: #28a745; color: #fff; }
        .payment-status-failed { background-color: #dc3545; color: #fff; }
        
        .notification {
            position: fixed;
            top: 20px;
            right: 20px;
            z-index: 1050;
            min-width: 300px;
        }
        
        .connection-status {
            position: fixed;
            top: 20px;
            left: 20px;
            z-index: 1050;
        }
        
        .stats-card {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
        
        .order-item {
            border-bottom: 1px solid #eee;
            padding: 10px 0;
        }
        
        .order-item:last-child {
            border-bottom: none;
        }
        
        .real-time-indicator {
            animation: pulse 2s infinite;
        }
        
        @keyframes pulse {
            0% { opacity: 1; }
            50% { opacity: 0.5; }
            100% { opacity: 1; }
        }
    </style>
</head>
<body>
    <div class="container-fluid">
        <!-- 连接状态指示器 -->
        <div class="connection-status">
            <div class="alert alert-info" id="connectionStatus">
                <i class="fas fa-circle text-danger"></i> 连接中...
            </div>
        </div>
        
        <!-- 页面标题 -->
        <div class="row mb-4">
            <div class="col-12">
                <h1 class="text-center">
                    <i class="fas fa-headphones text-primary"></i> 实时听单系统
                    <span class="badge bg-success real-time-indicator">实时</span>
                </h1>
            </div>
        </div>
        
        <!-- 统计信息 -->
        <div class="row mb-4">
            <div class="col-md-3">
                <div class="card stats-card">
                    <div class="card-body text-center">
                        <h5 class="card-title">总订单数</h5>
                        <h2 id="totalOrders">0</h2>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="card stats-card">
                    <div class="card-body text-center">
                        <h5 class="card-title">待处理</h5>
                        <h2 id="pendingOrders">0</h2>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="card stats-card">
                    <div class="card-body text-center">
                        <h5 class="card-title">已确认</h5>
                        <h2 id="confirmedOrders">0</h2>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="card stats-card">
                    <div class="card-body text-center">
                        <h5 class="card-title">已完成</h5>
                        <h2 id="completedOrders">0</h2>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 筛选和搜索 -->
        <div class="row mb-3">
            <div class="col-md-4">
                <select class="form-select" id="statusFilter">
                    <option value="">所有状态</option>
                    <option value="1">待确认</option>
                    <option value="2">已确认</option>
                    <option value="3">已支付</option>
                    <option value="4">已完成</option>
                    <option value="5">已取消</option>
                </select>
            </div>
            <div class="col-md-4">
                <input type="text" class="form-control" id="searchInput" placeholder="搜索订单号或用户ID">
            </div>
            <div class="col-md-4">
                <button class="btn btn-primary" onclick="refreshOrders()">
                    <i class="fas fa-sync-alt"></i> 刷新
                </button>
                <button class="btn btn-success" onclick="toggleAutoRefresh()">
                    <i class="fas fa-play" id="autoRefreshIcon"></i> <span id="autoRefreshText">自动刷新</span>
                </button>
            </div>
        </div>
        
        <!-- 订单列表 -->
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h5><i class="fas fa-list"></i> 实时订单列表</h5>
                    </div>
                    <div class="card-body">
                        <div id="ordersList">
                            <div class="text-center">
                                <div class="spinner-border" role="status">
                                    <span class="visually-hidden">加载中...</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- 通知容器 -->
    <div id="notificationContainer"></div>
    
    <!-- 订单详情模态框 -->
    <div class="modal fade" id="orderDetailModal" tabindex="-1">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">订单详情</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body" id="orderDetailContent">
                    <!-- 订单详情内容 -->
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="/static/js/websocket-client.js"></script>
</body>
</html>
